<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="98px">



      <el-form-item label="解约协议编号" prop="cfTerminationNo">
        <el-input
          v-model="queryParams.cfTerminationNo"
          placeholder="请输入解约协议编号"
          clearable

          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="解约日期" prop="terminationDate">
        <el-date-picker clearable size="small"
          v-model="queryParams.terminationDate"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择解约日期">
        </el-date-picker>
      </el-form-item>

      <el-form-item label="录入人姓名" prop="inputUserName">
        <el-input
          v-model="queryParams.inputUserName"
          placeholder="请输入录入人姓名"
          clearable

          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="录入日期" prop="inputDate">

        <el-date-picker clearable
          v-model="queryParams.inputDate"
          type="datetime"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="选择录入日期">
        </el-date-picker>
      </el-form-item>



      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">清除</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="terminationList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />

      <el-table-column label="解约协议编号" align="center" prop="cfTerminationNo" />
      <el-table-column label="小区(使用楼盘名)" align="center" prop="premiseName" />
      <el-table-column label="解约类型" align="center" prop="terminationType" />

      <el-table-column
        prop="terminationDate"
        label="解约日期"
        width="180">
      </el-table-column>
      <el-table-column
        prop="auditDate"
        label="审核日期"
        width="180">
      </el-table-column>

      <el-table-column label="结算合计(应退)， 为负数的时候是应收" align="center" prop="finalStatement" />
      <el-table-column label="录入人" align="center" prop="inputUserName" />
      <el-table-column label="录入日期" align="center" prop="inputDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.inputDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>

    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="商户ID" prop="businessId">
          <el-input v-model="form.businessId" placeholder="请输入商户ID" />
        </el-form-item>
        <el-form-item label="部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入部门ID" />
        </el-form-item>
        <el-form-item label="部门编号" prop="deptNo">
          <el-input v-model="form.deptNo" placeholder="请输入部门编号" />
        </el-form-item>
        <el-form-item label="解约协议编号" prop="cfTerminationNo">
          <el-input v-model="form.cfTerminationNo" placeholder="请输入解约协议编号" />
        </el-form-item>
        <el-form-item label="外部协议编号" prop="outTerminationNo">
          <el-input v-model="form.outTerminationNo" placeholder="请输入外部协议编号" />
        </el-form-item>
        <el-form-item label="出房合同ID" prop="cfContractId">
          <el-input v-model="form.cfContractId" placeholder="请输入出房合同ID" />
        </el-form-item>
        <el-form-item label="出房合同编号" prop="cfContractNo">
          <el-input v-model="form.cfContractNo" placeholder="请输入出房合同编号" />
        </el-form-item>
        <el-form-item label="楼盘ID" prop="premiseId">
          <el-input v-model="form.premiseId" placeholder="请输入楼盘ID" />
        </el-form-item>
        <el-form-item label="小区(使用楼盘名)" prop="premiseName">
          <el-input v-model="form.premiseName" placeholder="请输入小区(使用楼盘名)" />
        </el-form-item>
        <el-form-item label="房产编号" prop="houseId">
          <el-input v-model="form.houseId" placeholder="请输入房产编号" />
        </el-form-item>
        <el-form-item label="房产信息" prop="houseName">
          <el-input v-model="form.houseName" placeholder="请输入房产信息" />
        </el-form-item>
        <el-form-item label="房源ID" prop="roomId">
          <el-input v-model="form.roomId" placeholder="请输入房源ID" />
        </el-form-item>
        <el-form-item label="房源编号" prop="roomCode">
          <el-input v-model="form.roomCode" placeholder="请输入房源编号" />
        </el-form-item>
        <el-form-item label="房源名称" prop="roomName">
          <el-input v-model="form.roomName" placeholder="请输入房源名称" />
        </el-form-item>
        <el-form-item label="租客ID" prop="tenantId">
          <el-input v-model="form.tenantId" placeholder="请输入租客ID" />
        </el-form-item>
        <el-form-item label="租客姓名" prop="tenantName">
          <el-input v-model="form.tenantName" placeholder="请输入租客姓名" />
        </el-form-item>
        <el-form-item label="租客联系方式" prop="tenantPhone">
          <el-input v-model="form.tenantPhone" placeholder="请输入租客联系方式" />
        </el-form-item>
        <el-form-item label="解约类型" prop="terminationType">
          <el-select v-model="form.terminationType" placeholder="请选择解约类型">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="解约类型其他" prop="terminationOtherType">
          <el-select v-model="form.terminationOtherType" placeholder="请选择解约类型其他">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="物业交割日期" prop="wyjgDate">
          <el-date-picker clearable size="small"
            v-model="form.wyjgDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择物业交割日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="解约日期" prop="terminationDate">
          <el-date-picker clearable size="small"
            v-model="form.terminationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择解约日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同实际截止日" prop="realTerminationDate">
          <el-date-picker clearable size="small"
            v-model="form.realTerminationDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择合同实际截止日">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="审核日期" prop="auditDate">
          <el-date-picker clearable size="small"
            v-model="form.auditDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择审核日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="结算合计(应退)， 为负数的时候是应收" prop="finalStatement">
          <el-input v-model="form.finalStatement" placeholder="请输入结算合计(应退)， 为负数的时候是应收" />
        </el-form-item>
        <el-form-item label="录入人ID" prop="inputUserId">
          <el-input v-model="form.inputUserId" placeholder="请输入录入人ID" />
        </el-form-item>
        <el-form-item label="录入人姓名" prop="inputUserName">
          <el-input v-model="form.inputUserName" placeholder="请输入录入人姓名" />
        </el-form-item>
        <el-form-item label="录入日期" prop="inputDate">
          <el-date-picker clearable size="small"
            v-model="form.inputDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择录入日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="预留字段1" prop="reserve1">
          <el-input v-model="form.reserve1" placeholder="请输入预留字段1" />
        </el-form-item>
        <el-form-item label="预留字段2" prop="reserve2">
          <el-input v-model="form.reserve2" placeholder="请输入预留字段2" />
        </el-form-item>
        <el-form-item label="预留字段3" prop="reserve3">
          <el-input v-model="form.reserve3" placeholder="请输入预留字段3" />
        </el-form-item>
        <el-form-item label="预留字段4" prop="reserve4">
          <el-input v-model="form.reserve4" placeholder="请输入预留字段4" />
        </el-form-item>
        <el-form-item label="预留字段5" prop="reserve5">
          <el-input v-model="form.reserve5" placeholder="请输入预留字段5" />
        </el-form-item>
        <el-form-item label="删除标识：0:未删除，1：删除" prop="delFlg">
          <el-input v-model="form.delFlg" placeholder="请输入删除标识：0:未删除，1：删除" />
        </el-form-item>
        <el-form-item label="创建用户ID" prop="createUserid">
          <el-input v-model="form.createUserid" placeholder="请输入创建用户ID" />
        </el-form-item>
        <el-form-item label="更新用户ID" prop="updateUserid">
          <el-input v-model="form.updateUserid" placeholder="请输入更新用户ID" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTermination, getTermination, delTermination, addTermination, updateTermination } from "@/api/termination/termination";

export default {
  name: "Termination",
  components: {
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      terminationList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        businessId: null,
        deptId: null,
        deptNo: null,
        cfTerminationNo: null,
        outTerminationNo: null,
        cfContractId: null,
        cfContractNo: null,
        premiseId: null,
        premiseName: null,
        houseId: null,
        houseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        tenantId: null,
        tenantName: null,
        tenantPhone: null,
        terminationType: null,
        terminationOtherType: null,
        wyjgDate: null,
        terminationDate: null,
        realTerminationDate: null,
        auditDate: null,
        finalStatement: null,
        inputUserId: null,
        inputUserName: null,
        inputDate: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        updateUserid: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        roomId: [
          { required: true, message: "房源ID不能为空", trigger: "blur" }
        ],
        tenantId: [
          { required: true, message: "租客ID不能为空", trigger: "blur" }
        ],
        inputUserId: [
          { required: true, message: "录入人ID不能为空", trigger: "blur" }
        ],
        inputUserName: [
          { required: true, message: "录入人姓名不能为空", trigger: "blur" }
        ],
        inputDate: [
          { required: true, message: "录入日期不能为空", trigger: "blur" }
        ],
        delFlg: [
          { required: true, message: "删除标识：0:未删除，1：删除不能为空", trigger: "blur" }
        ],
        createUserid: [
          { required: true, message: "创建用户ID不能为空", trigger: "blur" }
        ],
        createTime: [
          { required: true, message: "创建时间不能为空", trigger: "blur" }
        ],
        updateUserid: [
          { required: true, message: "更新用户ID不能为空", trigger: "blur" }
        ],
        updateTime: [
          { required: true, message: "更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();

  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true;
      listTermination(this.queryParams).then(response => {
        this.terminationList = response.rows;
        response.rows.forEach(i=>{
          if(i.terminationType==1){
            i.terminationType="合同到期"
          }
          if(i.terminationType==2){
            i.terminationType="租客提前解约"
          }
          if(i.terminationType==3){
            i.terminationType="我方退租解约"
          }
          if(i.terminationType==4){
            i.terminationType="其他"
          }
        })
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        businessId: null,
        deptId: null,
        deptNo: null,
        cfTerminationNo: null,
        outTerminationNo: null,
        cfContractId: null,
        cfContractNo: null,
        premiseId: null,
        premiseName: null,
        houseId: null,
        houseName: null,
        roomId: null,
        roomCode: null,
        roomName: null,
        tenantId: null,
        tenantName: null,
        tenantPhone: null,
        terminationType: null,
        terminationOtherType: null,
        wyjgDate: null,
        terminationDate: null,
        realTerminationDate: null,
        auditDate: null,
        finalStatement: null,
        inputUserId: null,
        inputUserName: null,
        inputDate: null,
        remark: null,
        reserve1: null,
        reserve2: null,
        reserve3: null,
        reserve4: null,
        reserve5: null,
        delFlg: null,
        createUserid: null,
        createTime: null,
        updateUserid: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加【请填写功能名称】";
    },
    /** 按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getTermination(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "【请填写功能名称】";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateTermination(this.form).then(response => {
              this.msgSuccess("成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTermination(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除【请填写功能名称】编号为"' + ids + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTermination(ids);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/termination/export', {
        ...this.queryParams
      }, `system_termination.xlsx`)
    }
  }
};
</script>
